
#ifndef _MEMBER_BSONDOCUMENT_H_
#define _MEMBER_BSONDOCUMENT_H_

#include <BSonDocument>
#include "member_BSonNode.h"

#define sondoc_member(sondoc)	((member_BSonDocument*)((BSonDocument*)sondoc)->_ptr)

namespace BWE
{
	class member_BSonDocument
	{
	public:
		member_BSonDocument(BSonDocument* sondocument);
		~member_BSonDocument();

		const SonFormat* nodeFormat(const BSonNode* node);
		void makeFormat(BSonNode* node);
		bool appendText(BSonNode* node, BString& text, int level);
		bool removeTextIndent(BString& text, int level);

		bool readComment(BSonNode* node, const BString& sontext, int& pos);
		bool readNode(BSonNode* node, const BString& sontext, int& pos, int level);
		void writeNode(const BSonNode* node, BString& sontext, int level);
		void writeText(const BString& text, BString& sontext, int level);

		bool readComment(BSonNode* node, const BStream& stream);
		bool readNode(BSonNode* node, const BStream& stream, int level);
		void writeNode(const BSonNode* node, BStream& stream, int level);
		void writeText(const BString& text, BStream& stream, int level);

		BSonDocument*			boss;
		SonFormat				format;
		BSonNodeHolderArray		nodes;
		int						lineNumber;
		int						linePos;
		char					last;
		BString					log;
	};
}

#endif
